package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.service.MeunService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/main")
public class MainController {

    @Reference
    MeunService meunService;


    @RequestMapping("/findMeun")
    public Result findMeun(){
        try {
            User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            String username = user.getUsername();
            List<Map<String, Object>> meun = meunService.findMeun(username);
            return new Result(true,"查询成功",meun);
        } catch (Exception e) {
            return new Result(false,"查询失败");
        }
    }
}
